package org.example.practice.controller;

import org.example.commonapi.domain.R;
import org.example.commonapi.dto.LoginInfo;
import org.example.commonapi.dto.PageInfo;
import org.example.commonapi.util.JwtUtil;
import org.example.practice.service.PracticeHistoryService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;


@RestController
@RequestMapping("/practice")
public class PracticeHistoryController {

    @Resource
    private JwtUtil jwtUtil;

    @Resource
    private PracticeHistoryService practiceHistoryService;

    /**
     * 获取历史记录列表
     * @param request
     * @return
     */
    @GetMapping("/list/history")
    public R listHistory(@RequestParam(defaultValue = "1") Integer pageNum, @RequestParam(defaultValue = "10") Integer pageSize, HttpServletRequest request, String practiceName) {
        // 获取历史记录列表
        LoginInfo loginInfo=jwtUtil.parseJwt(request.getHeader("token"));
//        利用用户id查询
        PageInfo list=practiceHistoryService.listHistory(pageNum,pageSize,loginInfo,practiceName);
        return R.success(list);
    }

}
